<template>
  <page-main class="page-user-manage">
    <div class="btn-group align-right m-b-15">
      <el-button icon="el-icon-refresh" size="small" type="default" @click="getList()">刷新</el-button>  
      <el-button icon="el-icon-plus" size="small" type="primary" @click="$refs.addEdit.init('add')">新增</el-button>
    </div>
    <el-table
          v-loading="table_data.loading"
          ref="multipleTable"
          :data="table_data.list"
          stripe
          border
          size="medium"
          :height="tableHeight"
          style="width: 100%">
          <el-table-column label="序号" type="index" width="55" align="center" fixed />
          <el-table-column label="用户ID(唯一)" prop="user_id"/>
          <el-table-column label="用户名称" prop="user_name" />
          <el-table-column label="所属部门" prop="user_dept" />
          <el-table-column label="所属行政区域" prop="region_code" />
          <el-table-column label="是否为县区用户" prop="is_region_user" >
            <template slot-scope="scope">
              {{scope.row.is_region_user ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column label="是否为地市管理员" prop="is_region_admin" >
            <template slot-scope="scope">
              {{scope.row.is_region_admin ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column label="是否已锁定" prop="disabled">
            <template slot-scope="scope">
              {{scope.row.disabled ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="memo" />
          <el-table-column label="操作" fixed="right" width="180px">
            <template slot-scope="scope">
              <el-link :underline="false" class="m-r-10" type="primary" icon="el-icon-edit" @click="$refs.addEdit.init('edit', scope.row)">编辑</el-link>
              <el-link :underline="false" class="m-r-10" type="primary" icon="el-icon-menu" @click="$refs.setPermission.init(scope.row)">菜单权限</el-link>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page.current"
          :page-size="page.size"
          :page-sizes="page_sizes"
          :total="page.total"
          background
          style="padding-top: 30px; text-align: center;"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="getList"
          @size-change="pageSizeChange"
        />
    <add-edit ref="addEdit" @confirm="getList()" />
    <set-permission ref="setPermission" />
  </page-main>
</template>
<script>
import addEdit from './components/addEdit';
import setPermission from './components/setPermission';
export default {
  components:{
    addEdit,
    setPermission
  },
  data() {
    return {
      table_data:{
        loading: true,
        list: [],
      },
      page:{
        current: 1,
        size: 10,
        total: 0,
      },
      page_sizes:[10,20,30,60,100],
      domHeight: 0,
      tableHeight: 0,
    }
  },
  created() {
    this.domHeight = document.body.clientHeight - 64 - 40 - 48*2 - 10;
    this.tableHeight = this.domHeight -47-60;
    this.getList();
  },
  watch:{
    $route(to,from){
      this.$refs.multipleTable.doLayout();
    }
  },
  methods: {
    getList(page,size){
      this.table_data.loading = true;
      let params = {
        page_num : page || 1,
        page_count : size || this.page.size
      };
      params.page_num -= 1;
      this.$request('get', '/user/get_all_users', params, (data,msg) => {
        this.table_data.list = data.data;
        this.page.total = data.total;
        this.table_data.loading = false;
      })
    },
    pageSizeChange(val){
      this.page.size=val;
      this.getList(1, val);
    },
    handleOperate(name,row,type){

    },
  }
}
</script>